#include "Stack.h"
// 顺序栈

void InitSatck(Stack *s, int size)
{
    s->array_ = (DataType *)malloc(sizeof(DataType) * size);
    if (s->array_ == NULL)
    {
        perror("malloc fail");
        return;
    }
    s->capacity_ = size;
    s->length_ = 0;
}
void DestroyStack(Stack *s)
{
    free(s->array_);
    s->array_ = NULL;
    s->capacity_ = s->length_ = 0;
}
bool Empty(Stack *s)
{
    return s->length_ == 0;
}
bool Fill(Stack *s)
{
    return s->capacity_ == s->length_;
}
bool Pop(Stack *s, DataType *val)
{
    if (Empty(s))
        return false;
    *val = s->array_[s->length_ - 1];
    s->length_--;
    return true;
}
bool Push(Stack *s, DataType val)
{
    if (Fill(s))
        return false;
    s->array_[s->length_] = val;
    s->length_++;
    return true;
}
DataType GetTop(Stack *s)
{
    if (Empty(s))
        return -1;
    return s->array_[s->length_ - 1];
}
